/*
 * @lc app=leetcode.cn id=1 lang=typescript
 *
 * [1] 两数之和
 */

// @lc code=start
function twoSum(nums: number[], target: number): number[] | void {
  const numbers = [...nums];
  numbers.sort((a: number, b: number) => a - b);
  for (let index = 0; index < numbers.length; index++) {
    for (let i = index + 1; i < numbers.length; i++)
      if (
        numbers[i] + numbers[index] > target ||
        numbers[i] + numbers[numbers.length - 1] < target
      ) {
        break;
      } else if (numbers[i] + numbers[index] === target) {
        const start = nums.indexOf(numbers[index]);
        const end = nums.lastIndexOf(numbers[i]);
        return [start, end];
      }
  }
}
// @lc code=end
